<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>授权安装</title>
        <link rel="shortcut icon" href="{$_W['siteroot']}{$_W['config']['upload']['attachdir']}/{if !empty($_W['setting']['copyright']['icon'])}{$_W['setting']['copyright']['icon']}{else}images/global/wechat.jpg{/if}" />
        <link href="{php echo EWEI_SHOPV2_LOCAL}static/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
        <link href="{php echo EWEI_SHOPV2_LOCAL}static/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
        <link href="{php echo EWEI_SHOPV2_LOCAL}static/css/animate.css" rel="stylesheet">
        <link href="{php echo EWEI_SHOPV2_LOCAL}static/css/v2.css?v=4.1.0" rel="stylesheet">
        <link href="{php echo EWEI_SHOPV2_LOCAL}static/css/common.css?v=2.0.0" rel="stylesheet">
        <link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_1460799380_9653542.css">	
        <script src="./resource/js/lib/jquery-1.11.1.min.js"></script>
        <script src="{php echo EWEI_SHOPV2_LOCAL}static/js/dist/jquery/jquery.gcjs.js"></script>
        <script src="./resource/js/app/util.js"></script>


        <script src="{php echo EWEI_SHOPV2_LOCAL}static/js/require.js"></script>
        <script src="./resource/js/app/config.js"></script>
        <script src="{php echo EWEI_SHOPV2_LOCAL}static/js/myconfig.js"></script>


        <script type="text/javascript">
                if (navigator.appName == 'Microsoft Internet Explorer') {
                    if (navigator.userAgent.indexOf("MSIE 5.0") > 0 || navigator.userAgent.indexOf("MSIE 6.0") > 0 || navigator.userAgent.indexOf("MSIE 7.0") > 0) {
                        alert('您使用的 IE 浏览器版本过低, 推荐使用 Chrome 浏览器或 IE8 及以上版本浏览器.');
                    }
                }
                myrequire.path = "{$_W['siteroot']}addons/ewei_shopv2/static/js/";
        </script>
    </head>


<body class="white-bg ">
    
    
<div class='wrapper main-wrapper wrapper-content '>

    <div class="page-content" style="width:1000px">
	
<div class="page-heading"><h2><i class="fa fa-circle-o"></i>系统安装 </h2></div>

{if  empty($result['status'])}
    <form action="" method="post" class="form-horizontal form-validate" enctype="multipart/form-data" >
      
                <div class="form-group">
                    <label class="col-sm-2 control-label">域名</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="domain" class="form-control" value="{$domain}" readonly/>
                        <span class="help-block">服务器域名</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">站点IP</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="ip" class="form-control" value="{$ip}" readonly/>
                        <span class="help-block">站点IP</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">站点ID</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="id" class="form-control" value="{$id}" readonly />
                        <span class="help-block">站点ID,如果为空，请到 <a href='{php echo url('cloud/profile')}'>站点注册</a> 绑定您的服务器</span>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">授权码</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="code" class="form-control" value="{$auth['code']}" data-rule-required='true' data-msg-required='请填写授权码' />
                        <span class="help-block">请联系客服将IP及站点ID提交给客服, 索取授权码，保护好您的授权码，避免泄漏</span>
                    </div>
                </div>
 
             
                <div class="form-group">
                    <label class="col-sm-2 control-label">官方网站</label>
                    <div class="col-sm-9 col-xs-12">
                        <div class='form-control-static'><a href='http://www.we7shop.cn' target='_blank'>http://www.we7shop.cn</a></div>
                        {if empty($result['status'])}
                        <span class='help-block'>如果您正在使用非正版授权，请您尊重我们的劳动成果，谢谢您~</span>
                        <span class='help-block'>盗版有风险，请谨慎使用!</span>
                        {else}
                        {/if}
                    </div>
                </div>
             
				
                <div class="form-group">
                    <label class="col-sm-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                        <div class='form-control-static'>
                            <input type="submit"  value="验证授权并安装人人店V2" class="btn btn-primary" />
                        </div>
                    </div>
                </div>
</form>
{else}
<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" >

    <div class="form-group">
	<label class="col-sm-2 control-label">当前版本</label>
	<div class="col-sm-9 col-xs-12">
	    <div class="input-group">
		<div class="input-group-addon" style="background:#f2f2f2">{$version}</div>
		<input type='text' class='form-control'  value="RELEASE {$release}" readonly style="background:#fff;"/>
		<div class="input-group-btn"> 
		    <a class='btn btn-default' href="{php echo webUrl('system/auth/upgrade/checkversion')}" >降级版本更新</a>
		</div>
	   </div>
    </div>
	</div>
    <div class="form-group" >
	<label class="col-sm-2 control-label">最新版本</label>
	<div class="col-sm-9 col-xs-12">
	    <div class="form-control-static"  id="check">等待检测...</div>
	</div>
    </div>
    <div class="form-group" id="upgrade" style="display:none">
	<label class="col-sm-2 control-label"></label>
	<div class="col-sm-9 col-xs-12">
	    <div class='form-control-static'>
		<input type="button" id="upgradebtn" value="立即更新" class="btn btn-primary" />
	    </div>
	</div>
    </div>  
</form>
<script language='javascript'>
        function process(action) {
            $.ajax({
                url: "{php echo webUrl('system/auth/upgrade/process')}",
                data: {action: action},
                type: 'post',
                dataType: 'json',
                success: function (ret) {
                    var status = ret.status;
		    var result = ret.result;
	var act = result.action;
 
                    if (act == 'database') {
			
                        if (status == 1) {
                            $('#upgradebtn').val("已更新 " + result.success + " 个数据 / 共 " + result.total + " 个数据");
                            process('database');
                        } else {
                            $('#upgradebtn').val("已成功更新 " + result.total + " 个数据");
		 
                            process('file');
                        }
			
			
                    } else if (act == 'file') {
                        
                        if (status == 1) {
                            $('#upgradebtn').val("已更新 " + result.success + " 个文件 / 共 " + result.total + " 个文件");
                            process('file');
                        } else {
	       $('#upgradebtn').val("已成功更新 " + result.total + " 个文件");
	     
                            process('upgrade');
                        }

                    } else if (act== 'upgrade') {
		
	    
                        if (status == 1) {
			 
                             $('#upgradebtn').val("已更新 " + result.success + " 个补丁 / 共 " + result.total + " 个补丁");
                             process('upgrade');
                        } else {
			 
                             $('#upgradebtn').val('更新成功').removeAttr('updating');
                            tip.alert('更新成功!', function () {
                                location.href = "./index.php?c=site&a=entry&m=ewei_shopv2&do=web&r=system.auth.upgrade";
                            });
                        }
                    }
                }
            });
        }


        $(function () {


            $.ajax({
                url: "{php echo webUrl('system/auth/upgrade/check')}",
                type: 'post',
                dataType: 'json',
                success: function (ret) {
		    
	 var result = ret.result;

                    if (ret.status == 1) {
                       
                        var html = "";
                        
                        if (result.filecount <= 0 && !result.database && !result.upgrades) {

                            html += "恭喜您，您现在是最新版本！"

                        } else {

                            html += "最新版本: <span style='color:red'>" + result.version + "</span> RELEASE " + result.release +"<br/>";
 
                            if (result.filecount > 0) {
                                html += "共检测到有 <span style='color:red'>" + result.filecount + "</span> 个文件需要更新.<br/>";
                            }
                            if (result.database || result.upgrades) {
                                html += "此次有数据变动.<br/>";
                            }
                              if(result.templatefiles!=''){
	                           html += "<br/><b>模板更新</b><br/>";
                                               html += "<div style='height:150px;width:700px;overflow:auto;border:1px solid #f2f2f2;padding:5px;margin-top:10px;'>" + result.templatefiles + "</div><br/>";
	          }
			 
                            if (result.log != '') {
                                html += "<br/><b>更新日志:</b><br/>";
                                html += "<div style='height:150px;width:700px;overflow:auto;border:1px solid #f2f2f2;padding:5px;margin-top:10px;'>" + result.log + "</div><br/>";
                            }
                     
			    
			    
                            html += "<br/><b style='color:red'>更新之前请注意数据备份!</b><br/><br/>";
                        }

                        html += "<div id='process'></div>";
                        $("#check").html(html);
                        if (result.filecount > 0 || result.database || result.upgrades) {
                            $('#upgrade').show();
                            $("#upgradebtn").unbind('click').click(function () {
                                if ($(this).attr('updating') == '1') {
                                    return;
                                }
                                tip.confirm('确认已备份，并进行更新吗?', function () {
                                    $(this).attr('updating', 1).val('正在更新中...');
				    if( result.database){
					process('database');
				    } else if(result.filecount>0){
					process('file');
				    }else if(result.upgrades){
					process('upgrade');
				    }
                                    
                                });
                            });
                        }

                    } else {
		 
                        $("#check").html(result.message);
                    }
                }
            })


        })
</script>

{/if}
</div>
<script language='javascript'>
    $(function () {
        $('.page-content').show();
    });
</script>
<script language="javascript">myrequire(['web/init']);</script>
</body>
</html>
